import { Controller } from 'egg';
import { UserRole } from '../model/user';

export default class OrderedScheduleController extends Controller {
    /**
     * 老师和学生查看自己的预约排期
     */
    public async getOrderedSchedules() {
        const { ctx, service } = this;
        if (ctx.user.role === UserRole.Student) {
            const result = await service.orderedSchedule.getByStudent(ctx.user.id);
            ctx.helper.success(ctx, result);
        } else if (ctx.user.role === UserRole.Teacher) {
            const result = await service.orderedSchedule.getByTeacher(ctx.user.id);
            ctx.helper.success(ctx, result);
        } else {
            ctx.helper.invalidateRole();
        }
    }
}
